package today.rocky.pattern.factory.simplefactory;

import today.rocky.pattern.factory.common.Cestbon;
import today.rocky.pattern.factory.common.NongfuSpring;
import today.rocky.pattern.factory.common.Water;

/**
 * @version 1.0
 * @vlog:
 * @description:
 * @author: Rocky
 * @createDate: 2020/7/27 23:37
 */
public class SimpleWaterFactory {
	/**
	 * 通过名字获取
	 * @param type
	 * @return
	 */
	public Water getWater(String type){
		if (type.equals("cestbon")){
			return new Cestbon();
		}
		if(type.equals("nongfu")){
			return new NongfuSpring();
		}
		return null;
	}

	public Water getWater(Class<?> clazz){
		try {
			return  (Water)clazz.newInstance();
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
		return null;
	}



}
